package com.example.sport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.sport.domain.AthleteEventResult;
import com.example.sport.domain.College;
import com.example.sport.domain.User;
import com.example.sport.mapper.AthleteEventResultMapper;
import com.example.sport.mapper.UserMapper;
import com.example.sport.service.AthleteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AthleteServiceImpl implements AthleteService {

    @Autowired
    private AthleteEventResultMapper athleteEventResultMapper;

    @Override
    public List<AthleteEventResult> getAthleteEventResultsByUserId(String userId) {
        return athleteEventResultMapper.getAthleteEventResultsByUserId(userId);
    }

    @Override
    public List<AthleteEventResult> getAthleteEventResultsByCollegeId(String collegeId) {
        return athleteEventResultMapper.getAthleteEventResultsByCollegeId(collegeId);
    }

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUserByRoleAndName(String name, String role) {
        QueryWrapper<User> queryWrapper = new QueryWrapper();
        queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.eq("role", role);
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public List<User> getUserDetailListByRoleAndName(String name, String role) {
        return userMapper.getUserDetailListByRoleAndName(name, role);
    }

    @Override
    public int updateAthlete(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int addCollage(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User getUserById(String id) {
        return userMapper.selectById(id);
    }


}
